package com.neuedu.corejava.ch10;

import java.util.TreeSet;

public class TreeSetClass {

	public static void main(String[] args) {
		TreeSet<Computer> treeSet = new TreeSet<>();
		
		//TreeSet保存的数据类型需要实现java.lang.Comparable接口，如果没有实现，会报类型转换异常
		treeSet.add(new Computer("HP",5000));
		treeSet.add(new Computer("MP",4000));
		treeSet.add(new Computer("CP",3000));
		treeSet.add(new Computer("OP",6000));
		treeSet.add(new Computer("EP",4000));
		treeSet.add(new Computer("AP",3000));
		treeSet.add(new Computer("DP",5000));
		
		//需要实现Comparable接口并重写compareTo方法才能进行排序输出
		Computer computer = treeSet.first();
		System.out.println("fist"+computer);
		computer = treeSet.last();
		System.out.println("last"+computer);
		
		
		//以队列形式进行操作
		//computer = treeSet.pollFirst();
		computer = treeSet.pollLast();
		while (computer!=null) {
			System.out.println(computer);	
			//computer = treeSet.pollFirst();
			computer = treeSet.pollLast();
		}
		

	}

}
